package com.martinwj.service.impl;

import com.martinwj.dao.history.IHistoryDAO;
import com.martinwj.entity.History;
import com.martinwj.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: HistoryServiceImpl
 * @Description: TODO
 * @author: martin-wj
 * @createDate: 2021-04-04
 */
@Service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private IHistoryDAO iHistoryDAO;

    /**
     * 保存用户的播放记录
     * @param history
     */
    public void save(History history) {
        // 1.0 删除该记录
        iHistoryDAO.delete(history);

        // 2.0 添加该记录
        history.setUpdateTime(new Date());
        iHistoryDAO.insert(history);
    }

    /**
     * 获取用户最新的5条历史记录
     * @param userId 用户id
     * @return
     */
    public List<Map<String, Object>> listHistory5(String userId) {
        return iHistoryDAO.listHistory5(userId);
    }

    /**
     * 获取用户的历史记录列表
     * @param userId 用户id
     * @return
     */
    public List<Map<String, Object>> listHistory(String userId) {
        return iHistoryDAO.listHistory(userId);
    }

    /**
     * 删除历史记录
     * @param history
     */
    public void delete(History history) {
        iHistoryDAO.delete(history);
    }

}
